extends NodeState


var ball: Ball:
	get:
		return state_matchine.root as Ball


func _on_process(delta : float) -> void:
	process_animation()
	process_friction(delta)
	ball.process_bounce(delta, ball.bounciness)



func _on_enter(_data: NodeStateData) -> void:
	pass


func _on_exit() -> void:
	pass


# 摩擦力
func process_friction(delta : float):
	if absf(ball.velocity.x) > GlobalConstants.TINY:
		ball.move_and_bounce(delta)
		ball.velocity = ball.velocity.move_toward(Vector2.ZERO, ball.friction_ground * delta)




func process_animation():
	if ball.velocity.x > GlobalConstants.TINY:
		ball.animation_player.play(Ball.ANIMATION_ROLL)
	elif ball.velocity.x < GlobalConstants.TINY_NEGATIVE:
		ball.animation_player.play(Ball.ANIMATION_ROLL_BACK)
	else:
		ball.animation_player.play(Ball.ANIMATION_IDLE)